﻿
using System;
using System;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using AnyOffice.Components;
using AnyOffice.DAL;
using AnyOffice.Model;

namespace AnyOffice.general.system.menu
{
    public partial class func_edit : ModulePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.Page.IsPostBack)
            {
                int funcId = (Request.QueryString["func_id"] != null) ? Convert.ToInt32(Request.QueryString["func_id"].ToString()) : 0;
                this.ViewState["FuncId"] = funcId;
                DataTable table = new SysFunctionDao().SelectByFuncId(base.Conn, funcId);
                if (table.Rows.Count > 0)
                {
                    this.txtMenuId.Value = table.Rows[0]["MenuId"].ToString();
                    this.txtFuncName.Value = table.Rows[0]["FuncName"].ToString();
                    this.txtFuncCode.Value = table.Rows[0]["FuncCode"].ToString();
                    this.txtFuncImg.Value = table.Rows[0]["FuncImg"].ToString();
                }
            }
            if (this.Page.IsPostBack)
            {
                this.pnlMain.Visible = false;
                int num2 = Convert.ToInt32(this.ViewState["FuncId"].ToString());
                SysFunctionDao dao = new SysFunctionDao();
                DataTable table2 = dao.SelectByMenuId(base.Conn, this.txtMenuId.Value);
                if ((table2.Rows.Count > 0) && (Convert.ToInt32(table2.Rows[0]["FuncId"].ToString()) != num2))
                {
                    this.litMessage.Text = base.ShowPrompt("子菜单项代码已存在！");
                }
                else
                {
                    DataTable table3 = dao.SelectByFuncCode(base.Conn, this.txtFuncCode.Value);
                    if ((table3.Rows.Count > 0) && (Convert.ToInt32(table3.Rows[0]["FuncId"].ToString()) != num2))
                    {
                        this.litMessage.Text = base.ShowPrompt("子菜单模块路径已存在！");
                    }
                    else
                    {
                        SysFunctionData data = new SysFunctionData();
                        data.FuncId = Convert.ToInt32(this.ViewState["FuncId"].ToString());
                        data.MenuId = this.txtMenuId.Value;
                        data.FuncName = this.txtFuncName.Value;
                        data.FuncCode = this.txtFuncCode.Value;
                        data.FuncImg = this.txtFuncImg.Value;
                        dao.Update(base.Conn, data);
                        this.litMessage.Text = base.ShowMessage("修改成功！") + "<script>parent.menu_list.location.reload();</script>";
                    }
                }
            }
        } 

    }
}
